class Exploitdb < Formula
  desc "Database of public exploits and corresponding vulnerable software"
  homepage "https://www.exploit-db.com/"
  url "https://github.com/offensive-security/exploitdb.git",
      tag:      "2022-02-17",
      revision: "a300bd948f7bb7977066bbc5770fef7bbb3acd6f"
  version "2022-02-17"
  license "GPL-2.0-or-later"
  head "https://github.com/offensive-security/exploitdb.git", branch: "master"

  bottle do
    sha256 cellar: :any_skip_relocation, arm64_monterey: "ff7e00dbb31bff6223a946dc823ccd7735060fbfbe6a278c94c4c0f0db687986"
    sha256 cellar: :any_skip_relocation, arm64_big_sur:  "a39756064b5cc942cd80d60c52cc9853bfffab0dc9e53fee1717278f1f7d44ff"
    sha256 cellar: :any_skip_relocation, monterey:       "1ffe77ba623c8df5c1a80c9073b8fbf36bdef3e1e13a1d11ce7d3a0e03dbfdd5"
    sha256 cellar: :any_skip_relocation, big_sur:        "fb5cfb8178fe0c581e547fac53ef100eba48d9c8ec910ba5f6e36b59a3d43aa8"
    sha256 cellar: :any_skip_relocation, catalina:       "8c5b52a45094c65baee810d8c8d55fb0b10acbb1b0770cfaf49aa5d16a8ca50f"
    sha256 cellar: :any_skip_relocation, x86_64_linux:   "e403f57f17b16dd4e28891393432553d422d4a0074767d598b0514ade9c1bc56"
  end

  def install
    inreplace "searchsploit",
              "rc_file=\"\"", "rc_file=\"#{etc}/searchsploit_rc\""

    optpath = opt_share/"exploitdb"
    inreplace ".searchsploit_rc" do |s|
      s.gsub! "\"/opt/exploitdb\"", optpath
      s.gsub! "\"/opt/exploitdb-papers\"", "#{optpath}-papers"
    end

    bin.install "searchsploit"
    etc.install ".searchsploit_rc" => "searchsploit_rc"

    pkgshare.install %w[.git exploits files_exploits.csv files_shellcodes.csv
                        shellcodes]
  end

  test do
    system "#{bin}/searchsploit", "sendpage"
  end
end
